﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using Xpedite.Localization;
using Xpedite.Resources;
using Xpedite.Resources.Builders;
using Xpedite.Resources.Combiners;
using Xpedite.Resources.Definitions;

/* Copyright (c) 2010 CBaxter
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), 
 * to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 
 * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 
 * IN THE SOFTWARE. 
 */

namespace Xpedite.Test.Resources.Definitions
{
  [TestClass]
  public class ResourceDefinitionFactoryTest
  {
    private readonly Mock<IResourceBuilderFactory> _builderFactory = new Mock<IResourceBuilderFactory>(MockBehavior.Strict);
    private readonly Mock<IResourceUrlGenerator> _urlGenerator = new Mock<IResourceUrlGenerator>(MockBehavior.Strict);
    private readonly Mock<ICombinerFactory> _combinerFactory = new Mock<ICombinerFactory>(MockBehavior.Strict);
    private readonly Mock<IResourceContainer> _resource = new Mock<IResourceContainer>(MockBehavior.Strict);
    private readonly Mock<IResourceCache> _cache = new Mock<IResourceCache>(MockBehavior.Strict);
    private readonly Mock<ICombiner> _combiner = new Mock<ICombiner>(MockBehavior.Strict);
    private readonly IResourceDefinitionFactory _definitionFactory;

    public ResourceDefinitionFactoryTest()
    {
      _definitionFactory = new ResourceDefinitionFactory(new DefinitionArgs(_cache.Object, _urlGenerator.Object, _builderFactory.Object, _combinerFactory.Object));
    }
    
    [TestMethod]
    public void TestCreateCssDefinition()
    {
      Assert.IsTrue(typeof(CssDefinition).IsAssignableFrom(_definitionFactory.Create(ResourceType.Css, "MyResource").GetType()));
    }

    [TestMethod]
    public void TestCreateJavaScriptDefinition()
    {
      Assert.IsTrue(typeof(JavaScriptDefinition).IsAssignableFrom(_definitionFactory.Create(ResourceType.JavaScript, "MyResource").GetType()));
    }

    [TestMethod]
    public void TestCreateSpriteDefinition()
    {
      Assert.IsTrue(typeof(SpriteDefinition).IsAssignableFrom(_definitionFactory.Create(ResourceType.Png, "MyResource").GetType()));
      Assert.IsTrue(typeof(SpriteDefinition).IsAssignableFrom(_definitionFactory.Create(ResourceType.Jpeg, "MyResource").GetType()));
      Assert.IsTrue(typeof(SpriteDefinition).IsAssignableFrom(_definitionFactory.Create(ResourceType.Gif, "MyResource").GetType()));
    }

    [TestMethod]
    public void TestCreateUnknownDefinition()
    {
      Expect.Exception(() => _definitionFactory.Create(ResourceType.Unknown, "MyResource"), new XpediteException(String.Format(ExceptionMessages.ResourceTypeExpected, "MyResource")));
    }
  }
}
